module DocumentsHelper
  def document_name_value
    if action_name == "show"
      h @document.name 
    else
      text_field :document, :name 
    end
  end

  def document_version_value
    if action_name == "show"
      # not sure yet
    else
      file_field :document, :version
    end
  end

  def document_version_list_value
    rvalue = <<-TABLEDEF
      <table class="document_versions">
        <tr>
          <th>Version</th>
          <th>Content Type</th>
          <th>Size</th>
          <th>Actions</th>
        </tr>
    TABLEDEF
    current_version_number = DocumentVersion.current_version_id_for_document_id(@document.id)
    @document.document_versions.each do |doc|
      rvalue << %Q(<tr><td>#{doc.version_number.to_s}</td>)
      rvalue << %Q(<td>#{doc.version_content_type.to_s} </td>)
      rvalue << %Q(<td>#{doc.kilobytes.to_s}kb</td>)
      unless action_name == "show"
        unless  (doc.version_number.to_i == current_version_number.to_i)
          hsh = { :controller => "documents", :action => "destroy_version", 
                  :id => @document.id,
                  :document_category_id => @document_category.id,
                  :document_version_id => doc.id }
          links = [link_to('Destroy',hsh, :confirm => 'Are you sure?', :method => :delete )]
          rvalue << %Q(<td>#{links}</td>)
        end
      end
    end
    rvalue << "</table>"
  end
end
